home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / NetFractal™ / Fractal 8 source / CNetDemoApp.cp < prev    next >
Encoding:
Text File  |  1995-06-24  |  7.0 KB  |  272 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CNetDemoApp.cp                ©1995 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Example program showing how to use UModalDialogs
  6.  
  7. #include "CNetDemoApp.h"
  8.  
  9. #include "InPoint.h"
  10. #include "OutPoint.h"
  11.  
  12. #include "DemoDoc.h"
  13.  
  14. #include <LApplication.h>
  15. #include <LGrowZone.h>
  16. #include <LWindow.h>
  17. #include <UMemoryMgr.h>
  18. #include <UDrawingState.h>
  19. #include <URegistrar.h>
  20. #include <UReanimator.h>
  21.  
  22. #include <LEditField.h>
  23. #include <LTabGroup.h>
  24. #include <LCaption.h>
  25. #include <LRadioGroup.h>
  26. #include <LStdControl.h>
  27. #include <LDialogBox.h>
  28. #include <UModalDialogs.h>
  29. #include <PP_Messages.h>
  30.  
  31. #include <string.h>
  32.  
  33. #include "APane.h"
  34.  
  35. const ResIDT    WIND_NewSession = 128;
  36. const PaneIDT    pTCPButton        = 1;
  37. const PaneIDT    pAtalkButton    = 2;
  38. const PaneIDT    pAddress        = 11;
  39.  
  40. /*
  41. const ResIDT    WIND_Dashboard    = 200;
  42. const PaneIDT    capt_Number        = 301;
  43. const PaneIDT    capt_String        = 302;
  44.  
  45. const MessageT    msg_SetNumber    = 1000;
  46. const MessageT    msg_SetString    = 2000;
  47. const MessageT    msg_SetBoth        = 3000;
  48.  
  49. const ResIDT    WIND_SetNumber    = 1000;
  50. const PaneIDT    edit_Number        = 1001;
  51.  
  52. const ResIDT    WIND_SetString    = 2000;
  53. const PaneIDT    edit_String        = 2001;
  54.  
  55. const ResIDT    WIND_SetBoth    = 3000;
  56. const PaneIDT    edit_Number1    = 3001;
  57. const PaneIDT    edit_String1    = 3002;
  58. */
  59.  
  60.  
  61. // ===========================================================================
  62. //        • Main Program
  63. // ===========================================================================
  64.  
  65. void main(void)
  66. {
  67.     try {
  68.                                         // Set Debugging options
  69.         SetDebugThrow_(debugAction_Alert);
  70.         SetDebugSignal_(debugAction_Alert);
  71.     
  72.         InitializeHeap(3);                // Initialize Memory Manager
  73.                                         // Parameter is number of Master Pointer
  74.                                         //   blocks to allocate
  75.         
  76.                                         // Initialize standard Toolbox managers
  77.         UQDGlobals::InitializeToolbox(&qd);
  78.         InitOpenTransport();    
  79.     
  80.         new LGrowZone(20000);            // Install a GrowZone function to catch
  81.                                         //    low memory situations.
  82.                                         //    Parameter is size of reserve memory
  83.                                         //    block to allocated. The first time
  84.                                         //    the GrowZone function is called,
  85.                                         //    there will be at least this much
  86.                                         //    memory left (so you'll have enough
  87.                                         //    memory to alert the user or finish
  88.                                         //    what you are doing).
  89.         
  90.         CNetDemoApp    theApp;            // Create instance of your Application
  91.         theApp.Run();                    //   class and run it
  92.     }
  93.     catch(...) {
  94.         DebugStr("\pSomething's really hosed");
  95.     }
  96. }
  97.  
  98.  
  99. // ===========================================================================
  100. //        • CNetDemoApp Class
  101. // ===========================================================================
  102.  
  103. // ---------------------------------------------------------------------------
  104. //        • CNetDemoApp
  105. // ---------------------------------------------------------------------------
  106. //    Constructor
  107.  
  108. CNetDemoApp::CNetDemoApp()
  109. {
  110.         // Register classes for objects created from 'PPob' resources
  111.         // For PowerPlant classes, you can copy the necessary RegisterClass
  112.         // calls from PPobClasses.cp
  113.         //
  114.         // For your own classes, you must use the same four-character ID as
  115.         // you specify in the 'PPob' resource (or in Constructor).
  116.         // PowerPlant reserves all ID's composed entirely of lower case
  117.         // letters.
  118.         //
  119.         // The convention in PowerPlant is to define a local enumerated
  120.         // constant called class_ID for the four-character ID of each class.
  121.         
  122.     URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
  123.     URegistrar::RegisterClass(LEditField::class_ID, LEditField::CreateEditFieldStream);
  124.     URegistrar::RegisterClass(LTabGroup::class_ID, LTabGroup::CreateTabGroupStream);
  125.     URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
  126.     URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
  127.     URegistrar::RegisterClass(LStdRadioButton::class_ID, LStdRadioButton::CreateStdRadioButtonStream);
  128.     URegistrar::RegisterClass(LRadioGroup::class_ID, LRadioGroup::CreateRadioGroupStream);
  129.     URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
  130.     URegistrar::RegisterClass(APane::class_ID, APane::CreateAPaneStream);
  131. }
  132.  
  133.  
  134. // ---------------------------------------------------------------------------
  135. //        • ~CNetDemoApp
  136. // ---------------------------------------------------------------------------
  137. //    Destructor
  138.  
  139. CNetDemoApp::~CNetDemoApp()
  140. {
  141.         // +++ Add code here to cleanup (if necessary) before quitting
  142. }
  143.  
  144.  
  145. // ---------------------------------------------------------------------------
  146. //        • ObeyCommand
  147. // ---------------------------------------------------------------------------
  148. //    Respond to commands
  149.  
  150. Boolean
  151. CNetDemoApp::ObeyCommand(
  152.     CommandT    inCommand,
  153.     void        *ioParam)
  154. {
  155.     Boolean    cmdHandled = true;
  156.     
  157.     switch (inCommand) {
  158.         
  159.         case cmd_New:
  160.         case 999:
  161.             SpawnSender(inCommand == cmd_New);            // yes this is ugly... deal with it
  162.             break;
  163.     
  164.         // +++ Add cases here for the commands you handle
  165.         //        Remember to add same cases to FindCommandStatus below
  166.         //        to enable/disable the menu items for the commands
  167.     
  168.         default:
  169.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  170.             break;
  171.     }
  172.     
  173.     return cmdHandled;
  174. }
  175.  
  176.  
  177. // ---------------------------------------------------------------------------
  178. //        • FindCommandStatus
  179. // ---------------------------------------------------------------------------
  180. //    Pass back status of a (menu) command
  181.  
  182. void
  183. CNetDemoApp::FindCommandStatus(
  184.     CommandT    inCommand,
  185.     Boolean        &outEnabled,
  186.     Boolean        &outUsesMark,
  187.     Char16        &outMark,
  188.     Str255        outName)
  189. {
  190.     outUsesMark = false;
  191.     
  192.     switch (inCommand) {
  193.     
  194.         // +++ Add cases here for the commands you handle.
  195.         //
  196.         //        Set outEnabled to TRUE for commands that can be executed at
  197.         //        this time.
  198.         //
  199.         //        If the associated menu items can have check marks, set
  200.         //        outUsesMark and outMark accordingly.
  201.         //
  202.         //        Set outName to change the name of the menu item
  203.     
  204.         case cmd_New:
  205.             outEnabled = true;
  206.             break;
  207.     
  208.         default:
  209.             LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  210.                                 outMark, outName);
  211.             break;
  212.     }
  213. }
  214.  
  215.  
  216.  
  217. void
  218. CNetDemoApp::SpawnSender(
  219.     Boolean inSender)
  220.  
  221. {
  222.     StDialogHandler dlog(WIND_NewSession, this);
  223.     MessageT msg = 0;
  224.     
  225.     while (!msg)
  226.         msg = dlog.DoDialog();
  227.  
  228.     if (msg == msg_Cancel)
  229.         return;
  230.  
  231.     LWindow *window = LWindow::CreateWindow(129, this);
  232.  
  233.     Str255 address;
  234.     char configstr[80];
  235.     
  236.     LEditField* adrStr = (LEditField*) dlog.GetDialog()->FindPaneByID(pAddress);
  237.     LStdRadioButton* tcpBut = (LStdRadioButton*) dlog.GetDialog()->FindPaneByID(pTCPButton);
  238.     
  239.     if (tcpBut->GetValue())
  240.         strcpy(configstr, "udp");
  241.     else
  242.         strcpy(configstr, "ddp");
  243.     
  244.     adrStr->GetDescriptor(address);
  245.     p2cstr(address);
  246.  
  247.  
  248.     // for now we just create a sender
  249.     
  250.     volatile NetPoint* theNetPoint = nil;
  251.     
  252.     try {
  253.     
  254.     
  255.         if (inSender)
  256.             theNetPoint = new OutPoint(configstr, (char*) address, OUR_PORT);
  257.         else
  258.             theNetPoint = new InPoint(configstr, (char*) address, OUR_PORT);
  259.     
  260.     
  261.     }
  262.     catch(...) {
  263.         delete theNetPoint;
  264.     }
  265.  
  266.     DemoDoc* theDoc = new DemoDoc(this);
  267.     theDoc->SetNetPoint(theNetPoint);
  268.  
  269.  
  270. }
  271.  
  272.